
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Created by zhoub on 2019/12/9.
 */
public class SocketClient {
    public static void main(String[] args) throws IOException {
        String host = "10.0.65.211";
        int port = 8081;
        Socket socket = new Socket(host,port);
        while(true){
            InputStream inputStream = socket.getInputStream();
            byte[] buf = new byte[1024];
            int len=0;
            StringBuilder sb = new StringBuilder();
            while((len=inputStream.read(buf))!=-1){
                String receive = new String(buf,0,len,"UTF-8");
                sb.append(receive);
                if(receive.endsWith("eof")){
                    break;
                }
            }
            System.out.println("receive:"+sb.toString());

            OutputStream outputStream = socket.getOutputStream();
            outputStream.write("Hello,I'm Client eof".getBytes("UTF-8"));
            outputStream.flush();
        }
    }
}
